package com.qf.service.impl;

import com.qf.mapper.StatMapper;
import com.qf.pojo.DtsUser;
import com.qf.service.DtsStatService;
import com.qf.vo.*;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.text.SimpleDateFormat;
import java.util.Calendar;
import java.util.Date;
import java.util.List;

@Service
public class DtsStatServiceImpl implements DtsStatService {
    @Autowired
    StatMapper statMapper;

    /**
     * 查找销售类别
     * @return
     */
    @Override
    public List<CategorySellAmts> findCategorySell() {
        return statMapper.findCategorySell();
    }

    /**
     * 查询订单天数统计
     * @return
     */
    @Override
    public List<DayStatis> findOrderDayStatis() {
        Calendar calendar = Calendar.getInstance();

        //添加月份
        calendar.add(Calendar.MONTH,-1);

        //获取时间
        Date date = calendar.getTime();

        //日期格式化
        SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd 08:00:00");
        //将日期转成string
        String dateStr = sdf.format(date);

        return statMapper.findOrderDayStatis(dateStr);
    }

    /**
     * 查询用户数量
     * @return
     */
    @Override
    public List<DayStatis> findUserDayStatis() {
        Calendar calendar = Calendar.getInstance();
        calendar.add(Calendar.MONTH,-1);
        Date date = calendar.getTime();
        SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd 08:00:00");
        String dateStr = sdf.format(date);
        return statMapper.findUserDayStatis();
    }

    /**
     * 查找用户数量
     * @return
     */
    @Override
    public List<UserStatVo> findDaysAndUsers() {
        return statMapper.findUsersAndDays();
    }

    @Override
    public List<OrderStatVo> findDaysAndOrders() {
        return statMapper.findOrderAndDays();
    }

    @Override
    public List<GoodsStatVo> findDaysAndGoods() {
        return statMapper.findGoodsAndDays();
    }


}
